Repository navigation
fix(diff): read the index line after a dissimilarity index - #2353
Merged
Byron merged 1 commit intoNov 23, 2026
Merged
Conversation
With `-B`, Git writes `dissimilarity index N%` for a rewritten file, between the mode lines and the `index` line. `re_header` has no group for it, so the match stopped there: for a rewritten file `a_blob` and `b_blob` came back as `None`, and so did `a_mode` and `b_mode` when the mode had not changed (Git then puts it on the `index` line). The hunks were still read. Other files in the same `-B` diff were not affected. Accept the line, in the place Git writes it, before the `index` line. The new fixture is real `git diff -B --full-index` output for two rewritten files, one with a mode change and one without. `test_diff_with_dissimilarity_index` fails without this change. Agent-Model: claude-opus-5-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I am a Claude (Opus 5.5) agent working through the contributor's account.
Continuing the comparison of GitPython's parsers with what a current Git (2.56) prints, this time the patch header in
Diff._index_from_patch_format. WithB=True(git diff -B), a file that Git reports as rewritten came back witha_blobandb_blobset toNone, and with no modes either when the mode had not changed. The same diff without-Bhas them. Other files in a-Bdiff are not affected.For a broken pair Git writes
dissimilarity index N%between the mode lines and theindexline.re_headerhas no group for that line, and every group after it is optional, so the match ends there and theindexline is never read. The hunks are still parsed, so nothing warns.Accept the line, in the place Git writes it, before the
indexline.Validation on Linux, CPython 3.14.4, Git 2.56.0:
git diff -B --full-indexoutput for two rewritten files, one with a mode change and one without.test_diff_with_dissimilarity_indexfails on the originaldiff.py(a_blobisNone) and passes with the change.commit.diff(None, create_patch=True, B=True)on a real repository with the same two files: before, both had no blobs and the unchanged-mode file had no modes; after, both have the right blob ids and modes.test/test_diff.pyalso passes (51) withGIT_PYTHON_BACKEND=gix.Not run: mypy, the complete suite with the gix backend, other platforms and Python versions.